import Vue from 'vue'
import VueRouter from 'vue-router'
import HomeView from '../views/HomeView.vue'

Vue.use(VueRouter)

const routes = [
  {
    path: '/',
    name: 'home',
    meta:'首页',
    redirect:'/wecomto',
    component: HomeView,
    children: [
      {
        path: '/wecomto',
        name: 'wecomto',
        meta: '欢迎页',
        component: () => import('../views/wecomto.vue')
      },
      {
        path: '/users',
        name: 'user',
        meta: '用户列表',
        component: () => import('../views/user.vue')
      },
      {
        path: '/roles',
        name: 'roles',
        meta: '角色列表',
        component: () => import('../views/roles.vue')
      },
      {
        path: '/rights',
        name: 'rights',
        meta: '权限列表',
        component: () => import('../views/rights.vue')
      },
      {
        path: '/categories',
        name: 'categories',
        meta: '商品分类',
        component: () => import('../views/categories.vue')
      },
      {
        path: '/goods',
        name: 'goods',
        meta: '商品列表',
        component: () => import('../views/goods.vue')
      },
      {
        path: '/goodAdd',
        name: 'goodAdd',
        meta: '商品添加',
        component: () => import('../views/goodAdd.vue')
      },
      {
        path: '/categories',
        name: 'categories',
        meta: '分类列表',
        component: () => import('../views/categories.vue')
      },
      {
        path: '/params',
        name: 'params',
        meta: '分类参数',
        component: () => import('../views/params.vue')
      },
      {
        path: '/orders',
        name: 'orders',
        meta: '订单管理',
        component: () => import('../views/orders.vue')
      },
      {
        path: '/reports',
        name: 'reports',
        meta: '后台数据',
        component: () => import('../views/reports.vue')
      }
    ]
  },
  {
    path: '/login',
    name: 'login',
    component: () => import('../views/login.vue')
  },
  {
    path: '/about',
    name: 'about',
    component: () => import('../views/AboutView.vue')
  }
]

const router = new VueRouter({
  routes
})
router.beforeEach((to,from,next)=>{ 
if(to.path=='/login'){
 next()
   }else{
if(sessionStorage.getItem('token')){
 next()
 }else{
next('/login')
 }}})


export default router
